<!doctype html>
<html>

	<head>
		<meta charset="utf-8">
		<title></title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link href="css/mui.css" rel="stylesheet" />
		<link rel="stylesheet" type="text/css" href="css/style.css"/>
		<link rel="stylesheet" type="text/css" href="css/shop.css"/>
		<link rel="stylesheet" type="text/css" href="css/takeaway.css"/>
	</head>
	<body>
		
		<header class="mui-bar mui-bar-nav">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 class="mui-title">商品详情</h1>
		</header>
		
		<div class="mui-content">
			<div class="detail-div">
				<div class="detail-div-t">
					<img src="images/1-1.png" >
					<div class="spxq-div">
						<div class="wm-list-div-r-t-l info">
							<span class="mui-icon mui-icon-star-filled start-ys start-active"></span>
							<span class="mui-icon mui-icon-star-filled start-ys start-active"></span>
							<span class="mui-icon mui-icon-star-filled start-ys start-active"></span>
							<span class="mui-icon mui-icon-star-filled start-ys start-active"></span>
							<span class="mui-icon mui-icon-star-filled start-ys"></span>
						</div>
						<div>
							<span class="small-txt"><span class="info">52</span>评价</span>
							<span class="small-txt">月售<span class="info">3522</span>单</span>
							<div class="wm-list-div-r-tt">
								<div class="shop-list-div-jg">
									<h5> <span>¥</span><span class="big-txt info">35</span><span class="mui-icon mui-icon-plusempty mui-pull-right plus-icon  info"></span></h5>
								</div>
							</div>
						</div>
					</div>
				</div>
				<div class="detail-div-b">
					<div class="pj-list">
						<h5 class="mui-content-padded">客户评价</h5>
						<div class="pj-list-div punlic-clear-both">
							<div class="pj-list-div-l">
								<img src="images/head.jpg" >
							</div>
							<div class="pj-list-div-r">
								<p><span>不会飞的鱼</span><span class="mui-pull-right">2016-03-25</span></p>
								<div class="wm-list-div-r-t">
									<div class="wm-list-div-r-t-l">
										<span class="mui-icon mui-icon-star-filled start-ys start-active"></span>
										<span class="mui-icon mui-icon-star-filled start-ys start-active"></span>
										<span class="mui-icon mui-icon-star-filled start-ys start-active"></span>
										<span class="mui-icon mui-icon-star-filled start-ys start-active"></span>
										<span class="mui-icon mui-icon-star-filled start-ys"></span>
									</div>
									<span class="small-txt" style="margin-left: 5px;color: #999;">30分钟送达</span>
								</div>
								<p>饭送的很快，很给力，下拆来饭送的很快，很给力，下拆来</p>
							</div>
						</div>
						<div class="pj-list-div punlic-clear-both">
							<div class="pj-list-div-l">
								<img src="images/head.jpg" >
							</div>
							<div class="pj-list-div-r">
								<p><span>不会飞的鱼</span><span class="mui-pull-right">2016-03-25</span></p>
								<div class="wm-list-div-r-t">
									<div class="wm-list-div-r-t-l">
										<span class="mui-icon mui-icon-star-filled start-ys start-active"></span>
										<span class="mui-icon mui-icon-star-filled start-ys start-active"></span>
										<span class="mui-icon mui-icon-star-filled start-ys start-active"></span>
										<span class="mui-icon mui-icon-star-filled start-ys start-active"></span>
										<span class="mui-icon mui-icon-star-filled start-ys"></span>
									</div>
									<span class="small-txt" style="margin-left: 5px;color: #999;">30分钟送达</span>
								</div>
								<p>饭送的很快，很给力，下拆来饭送的很快，很给力，下拆来</p>
							</div>
						</div>
						<div class="pj-list-div punlic-clear-both">
							<div class="pj-list-div-l">
								<img src="images/head.jpg" >
							</div>
							<div class="pj-list-div-r">
								<p><span>不会飞的鱼</span><span class="mui-pull-right">2016-03-25</span></p>
								<div class="wm-list-div-r-t">
									<div class="wm-list-div-r-t-l">
										<span class="mui-icon mui-icon-star-filled start-ys start-active"></span>
										<span class="mui-icon mui-icon-star-filled start-ys start-active"></span>
										<span class="mui-icon mui-icon-star-filled start-ys start-active"></span>
										<span class="mui-icon mui-icon-star-filled start-ys start-active"></span>
										<span class="mui-icon mui-icon-star-filled start-ys"></span>
									</div>
									<span class="small-txt" style="margin-left: 5px;color: #999;">30分钟送达</span>
								</div>
								<p>饭送的很快，很给力，下拆来饭送的很快，很给力，下拆来</p>
							</div>
						</div>
						<div class="pj-list-div punlic-clear-both">
							<div class="pj-list-div-l">
								<img src="images/head.jpg" >
							</div>
							<div class="pj-list-div-r">
								<p><span>不会飞的鱼</span><span class="mui-pull-right">2016-03-25</span></p>
								<div class="wm-list-div-r-t">
									<div class="wm-list-div-r-t-l">
										<span class="mui-icon mui-icon-star-filled start-ys start-active"></span>
										<span class="mui-icon mui-icon-star-filled start-ys start-active"></span>
										<span class="mui-icon mui-icon-star-filled start-ys start-active"></span>
										<span class="mui-icon mui-icon-star-filled start-ys start-active"></span>
										<span class="mui-icon mui-icon-star-filled start-ys"></span>
									</div>
									<span class="small-txt" style="margin-left: 5px;color: #999;">30分钟送达</span>
								</div>
								<p>饭送的很快，很给力，下拆来饭送的很快，很给力，下拆来</p>
							</div>
						</div>
					</div>
					<div class="shop-car">
						<div class="shop-car-l">
							<span class="mui-icon mui-icon-paperplane fj-icon"></span>
							<span>¥<span class="info">0</span></span>
						</div>
						<div class="shop-car-r">
							<span>¥<span class="info">38</span>起送</span>
							<button id="btn">去付款</button>
						</div>
					</div>
				</div>
			</div>
		</div>
		
		<script src="js/mui.js"></script>
		<script src="js/castapp.js"></script>
		<script type="text/javascript">
			mui.init()
			ca.init()
			
			var item_id = localStorage.getItem('item_id')
			var request_url = localStorage.getItem("request_url")
			
			
			var info = ca.className('info')
			
			
			
			// alert(item_id)
			
			get_item()
			function get_item(){
				ca.get({
					url:request_url + "Item/get_one",
					data:{
						id_data:item_id
					},succFn:function(data){
						var json = JSON.parse(data)
						info['2'].innerHTML = json.buyNumber
						info['3'].innerHTML = json.price
						info['6'].innerHTML = json.price
					}
				})
			}

			info[4].addEventListener('tap',function(){
				info['5'].innerHTML = parseFloat(info['5'].innerHTML) + parseFloat(info['6'].innerHTML)
			})
			
			var btn = ca.id('btn')
			btn.addEventListener('tap',function(){
				var login_phone = localStorage.getItem("login_phone")
				if (!login_phone) {
					ca.prompt('请登录');
					ca.newInterface({
						url:'login.html',
						id:'login'
					})
					return
				}
				
				var money = info['5'].innerHTML
				if (parseFloat(money) < 0.00001) {
					ca.prompt('请选购付款')
					return
				}
				
				//订单流程 --> 产生订单(未付款) --> 跳转到支付页 --> 把订单状态改位已付款
				
				// var code = ca.getIdCode(10)
				//产生订单
				ca.get({
					url:request_url + 'Item/create_order',
					data:{
						phone_data:login_phone,
						item_id:item_id,
						money_data:money
					},succFn:function(orderID){
						if (orderID > 0) {
							
							var user_json =JSON.parse(localStorage.getItem("user_data"))
							// alert(user_json.money )
							if (parseFloat(user_json.money) >= parseFloat(money)) {
								//是否使用余额支付
								var btnArray = ['是','否']
								mui.confirm('是否使用账户余额支付',"订单支付",btnArray,function(e){
									if (e.index == 0) {
										ca.get({
											url:request_url + 'Item/money_pay',
											data:{
												phone_data:login_phone,
												money_data:money
											},succFn:function(data){
												if (data >= 0) {
													ca.prompt('下单成功')
													modState(orderID)
													user_json.money = data
													localStorage.setItem("user_data", JSON.stringify(user_json))
												} else {
													ca.prompt('下单失败')
												}
											}
										})
										
									} 						
								})
							} else {
								ca.prompt('支付宝支付')
								ca.prompt('下单成功')
								modState(orderID)
							}
							
							
							
						}
					}
				})
				
				
				// alert(code)
			})
			
			function modState(data) {
				ca.get({
					url:request_url + "Item/mod_state",
					data:{
						id_data:data
					},succFn:function(d){
						if(d == 0) {
							ca.prompt('下单成功')
						}  else {
							ca.prompt('下单失败')
						}
					}
				})
			}
		</script>
	</body>

</html>
